package com.wyk.service.impl;

import com.wyk.service.MessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;

/**因为这里使用的是Stream进行绑定，所以需要使用注解EnableBinding
 * @author WangYuKai
 * @Date 2022/7/17
 * @apiNote
 */
@EnableBinding(Source.class)//定义消息的推送管道
public class MessageProviderImpl implements MessageProvider {

    //注入信道
    @Autowired
    private MessageChannel output;

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        //发送消息
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("我发送的消息：" + serial);
        return null;
    }
}
